home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / compute / 1988_02 / lockout.asm < prev    next >
Assembly Source File  |  1987-09-24  |  8KB  |  282 lines

  1.         ;  Program: lockup.com
  2.         ;
  3.         ;  Author: Paul W. Carlson
  4.         ;
  5.         cseg    segment    para    public    'CODE'
  6.             assume    cs:cseg
  7.             org        100h
  8.         begin:    jmp    init
  9.         ;
  10.         lkey    db    38            ;scan code for L key
  11.     adapt    db    0            ;0 = CGA, 1 = MDA
  12.         onflag    db    0            ;busy flag
  13.     vmode    db    0            ;video mode
  14.     dmode    db    0            ;message display mode
  15.     pal     db      0
  16.         vpage    db    0            ;video page
  17.     bufsiz    dw    0            ;video buffer size
  18.     vidseg    dw    0            ;video segment
  19.     curpos    dw    0            ;cursor position
  20.         curmod    dw    0            ;cursor mode
  21.     envals    db    2ch,28h,2dh,29h,2ah,2eh,1eh
  22.     messag    db    'C',135,'O',135,'M',135,'P',135,'U',135
  23.         db    'T',135,'E',135,'R',135,' ',135,'I',135
  24.         db    'S',135,' ',135,'I',135,'N',135,' ',135
  25.         db    'U',135,'S',135,'E',135
  26.         oldint    label    dword            ;old interrupt vector
  27.         oldvec    dw    2    dup (0)
  28.     buffer    dw    offset init
  29.         ;
  30.         kbint    proc    near
  31.             cmp    onflag,0    ;are we holding?
  32.             jne    leave        ;yes, exit
  33.             sti            ;enable interrupts
  34.             push    ax        ;save registers
  35.             push    bx
  36.             push    cx
  37.             push    dx
  38.             push    si
  39.             push    di
  40.             push    ds
  41.             push    es
  42.             in    al,60h        ;get keyboard scan code
  43.             cmp    al,lkey        ;was the 'L' key pressed?
  44.             jne    exit        ;no, exit
  45.             mov    ah,2        ;get shift key status
  46.             int    16h        ;BIOS does it
  47.             and    al,8        ;is the Alt key depressed?
  48.             jne    gotit        ;yes, continue
  49.         exit:    pop    es        ;no, restore registersand exit
  50.             pop    ds
  51.             pop    di
  52.             pop    si
  53.             pop    dx
  54.             pop    cx
  55.             pop    bx
  56.             pop    ax
  57.         leave:    jmp    oldint        ;exit to BIOS routine
  58.         gotit:    call    kreset        ;reset keyboard and send EOI
  59.             push    cs        ;ds and es = cs
  60.             pop    ds
  61.             push    cs
  62.             pop    es
  63.             assume    ds:cseg
  64.             mov    ah,15        ;get video mode and page
  65.             int    10h        ;BIOS does it
  66.         cmp    al,8        ;is mode < 8 ?
  67.         jb    modeok        ;yes, mode ok
  68.         done:    pop    es        ;no, restore registers and exit
  69.             pop    ds
  70.             pop    di
  71.             pop    si
  72.             pop    dx
  73.             pop    cx
  74.             pop    bx
  75.             pop    ax
  76.             iret            ;return from interrupt
  77.     modeok:    mov    vmode,al    ;save video mode
  78.             push     es
  79.                 mov     ax,40h
  80.                 mov     es,ax
  81.                 mov     al,es:[66h]
  82.                 mov     pal,al
  83.                 pop     es
  84.         mov    vpage,bh    ;save video page
  85.                 mov    onflag,1    ;set flag to on
  86.             mov    ah,3        ;get the cursor shape
  87.             int    10h        ;BIOS does it
  88.             mov    curmod,cx    ;save it
  89.         mov    curpos,dx    ;save cursor position
  90.         cmp    adapt,0        ;CGA?
  91.         jne    sscrn        ;no
  92.             call    discga        ;disable CGA video
  93.        sscrn:     call    savscr        ;save screen contents
  94.             call    dismes        ;display the message
  95.         cmp    adapt,0        ;CGA?
  96.         jne    getkey        ;no
  97.             call    enacga        ;enable CGA video
  98.     getkey:    mov    ah,0        ;wait for keypress
  99.         int    16h        ;BIOS does it
  100.         cmp    ah,lkey        ;was 'L' key pressed?
  101.         jne    getkey        ;no, try again
  102.                    mov    ah,2        ;check keyboard status flags
  103.             int    16h        ;BIOS does it
  104.             and     al,8        ;Alt key pressed?
  105.         je    getkey        ;no, try again
  106.         cmp    adapt,0        ;CGA?
  107.         jne    setvmd        ;no
  108.                 call    discga
  109.     setvmd:    mov    ah,0        ;set video mode
  110.         mov    al,vmode
  111.         int    10h        ;BIOS does it
  112.             call    resscr        ;restore video memory contents
  113.         mov    ah,5        ;set video page
  114.         mov    al,vpage
  115.         int    10h        ;BIOS does it
  116.         cmp    vmode,3        ;is video mode > 3 ?
  117.         jbe    docur        ;no
  118.         cmp    vmode,7        ;video mode = 7 ?
  119.         jne    nocur        ;no, don't restore cursor
  120.     docur:    mov    ah,2        ;position cursor
  121.         mov    bh,vpage
  122.         mov    dx,curpos
  123.         int    10h        ;BIOS does it
  124.         cmp    adapt,0        ;CGA?
  125.         jne    nocur        ;no
  126.             call    enacga
  127.     nocur:    mov    ah,1        ;unblank the cursor
  128.             mov    cx,curmod    ;restore cursor scan lines
  129.             int    10h        ;BIOS does it
  130.             mov    onflag,0    ;set flag to off
  131.             mov     al,pal
  132.         and     al,32
  133.         jz     l1
  134.         mov     bl,1
  135.         jmp     l2
  136. l1:         mov     bl,0
  137. l2:        mov     ah,11
  138.             mov     bh,1
  139.             int    10h
  140.             mov     ah,11
  141.             mov     bh,0
  142.             mov     bl,pal
  143.             int     10h
  144.             jmp    done        ;exit
  145.         kbint    endp
  146.         ;
  147.         ;----    Procedure to save the user's screen
  148.         savscr    proc    near
  149.         push    ds        ;save data segment
  150.         assume    ds:nothing
  151.         mov    ax,vidseg    ;set ds to video RAM
  152.         mov    ds,ax
  153.         mov    di,buffer    ;init. dest. index
  154.         xor    si,si        ;init. source index
  155.         mov    cx,bufsiz    ;no. of words to move
  156.         cld            ;forward direction
  157.     rep    movsw            ;move the screen data to buffer
  158.         pop    ds        ;restore data segment
  159.         assume    ds:cseg
  160.         ret
  161.     savscr    endp
  162.         ;
  163.         ;----    Procedure to restore the screen
  164.         resscr    proc    near
  165.             push    es        ;save extra segment
  166.             assume    es:nothing
  167.             mov    ax,vidseg    ;set ex to video RAM
  168.             mov    es,ax
  169.             mov    si,buffer    ;init. source index
  170.         xor    di,di        ;init. dest. index
  171.         mov    cx,bufsiz    ;no. of words to move
  172.         cld            ;forward direction
  173.     rep    movsw            ;move buffer to screen
  174.         pop    es        ;restore extra segment
  175.         assume    es:cseg
  176.         ret
  177.     resscr    endp
  178.         ;
  179.         ;----    Procedure to display the message
  180.         dismes    proc    near
  181.         mov    ah,0        ;set video mode
  182.         mov    al,dmode    ;video mode 2
  183.         int    10h        ;BIOS does it
  184.         mov    ah,5        ;set video page
  185.         mov    al,0        ;video page 0
  186.         int    10h        ;BIOS does it
  187.         mov    ax,0600h    ;clear the screen
  188.         xor    cx,cx        ;from 0,0
  189.         mov    dx,0184fh    ;  to 24,79
  190.         mov    bh,7        ;set attribute
  191.         int    10h        ;BIOS does it
  192.         mov    ah,1        ;hide the cursor
  193.         mov    ch,32        ;set bit 5 of ch
  194.         int    10h        ;BIOS does it
  195.             push    es        ;save extra segment
  196.             assume    es:nothing
  197.         mov    ax,vidseg    ;set es to video RAM
  198.         mov    es,ax
  199.             lea    si,messag    ;set si to message
  200.             mov    di,1982        ;set di to video RAM offset
  201.             mov    cx,36        ;36 bytes to move
  202.     rep    movsb            ;display message
  203.         pop    es        ;restore extra segment
  204.         assume    es:cseg
  205.         ret
  206.     dismes    endp
  207.         ;
  208.         ;-----    Procedure to disable the CGA
  209.         discga    proc    near
  210.             mov    dx,3DAh        ;status register
  211.         wait:    in    al,dx        ;get status
  212.             test    al,8        ;in vertical retrace?
  213.             je    wait        ;no, try again
  214.             sub    dx,2        ;mode select register
  215.             mov    al,25h        ;turn off bit 3 to
  216.                   out    dx,al        ;   disable video
  217.             ret
  218.         discga    endp
  219.         ;
  220.         ;----    Procedure to enable the CGA
  221.         enacga    proc    near
  222.         mov    ah,15        ;get mode
  223.         int    10h        ;BIOS does it
  224.         lea    bx,envals    ;bx points to enable values
  225.         xlat            ;al has enable value
  226.                    mov    dx,3D8h        ;mode select register
  227.             out    dx,al        ;enable video
  228.             ret
  229.         enacga    endp
  230.         ;
  231.         ;---    Procedure to reset keyboard and send end-of-interrupt
  232.         kreset    proc    near
  233.             in    al,61h        ;get port value
  234.             mov    ah,al        ;save it in ah
  235.             or    al,80h        ;set bit 7
  236.             out    61h,al        ;reset port
  237.             mov    al,ah        ;send original value
  238.             out    61h,al        ;   to enable keyboard
  239.             cli            ;disable interrupts
  240.             mov    al,20h        ;20h is EOI
  241.             out    20h,al        ;send EOI
  242.             sti            ;enable interrupts
  243.             ret
  244.         kreset    endp
  245.         ;
  246.         ;----    Initialize, terminate and stay resident
  247.         init    proc    near
  248.             mov    adapt,0        ;assume CGA
  249.             mov    vidseg,0b800h
  250.         mov    bufsiz,8096
  251.         mov    dmode,2
  252.             mov    ah,15        ;get video mode
  253.             int    10h
  254.             cmp    al,7        ;is it mode 7?
  255.             jne    itscga        ;no, it's a CGA 
  256.             inc    adapt        ;yes, it's monochrome
  257.         mov    bufsiz,2048
  258.             sub    vidseg,800h    ;adjust segment for monochrome
  259.             mov    cx,0C0Dh    ;monochrome cursor
  260.         mov    dmode,7        ;display message mode 7
  261.             cmp    al,7        ;video mode 7?
  262.             jmp    short setcur    ;yes
  263.         itscga:    mov    cx,0607h    ;no, cursor scan lines 6 and 7
  264.         setcur:    mov    ah,1        ;set cursor
  265.             int    10h
  266.         ;---    Save the old interrupt 9 vector and replace it with ours
  267.             mov    ah,35h        ;get keyboard (int 9) vector
  268.             mov    al,9
  269.             int    21h
  270.             mov    oldvec,bx    ;save vector offset
  271.             mov    oldvec[2],es    ;save vector segment
  272.             mov    ah,25h        ;set vector to point to
  273.             mov    al,9        ;   our procedure
  274.             lea    dx,kbint
  275.             int    21h
  276.         ;---    Terminate and stay resident
  277.             mov    dx,offset init+16192
  278.             int    27h        ;terminate and stay resident
  279.         init    endp
  280.         cseg    ends
  281.             end    begin
  282.